



def b(a):
    s = 0
    for i in range(2, a):
        if a % i == 0:
            s = s + 1
    if s > 0:
        return 0
    else:
        return a
p = int(input())
p1 = p // 1000
p2 = p // 100 % 10
p3 = p // 10 % 10
p4 = p % 10
m=0
if 999 < p < 10000:
     s = p1
     k = b(s)
     if k > m:
         m = k
     s = p2 
     k = b(s)
     if k>m:
        m = k
     s = p3
     k = b(s)
     if k > m:
        m = k
     s = p4
     k = b(s)
     if k>m:
        m=k
     s = p1* 10 + p2
     k = b(s)
     if k > m:
        m = k
     s = p2 * 10 + p3
     k = b(s)
     if k>m:
        m=k
     s = p1 * 10 + p2
     k = b(s)
     if k>m:
        m=k
     s = p3 * 10 + p4
     k = b(s)
     if k>m:
        m=k
     s = p1 * 100 + p2 * 10 + p3
     k = b(s)
     if k > m:
        m = k
     s = p2 * 100 + p3 * 10 + p4
     k = b(s)
     if k > m:
        m = k
     s = p
     k = b(s)
     if k >  m:
        m = k
     print (m)
    
